package com.zlzxm.shoesmarket.view.adapter;

import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;

import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityGoodsSizeInfo;

import org.jetbrains.annotations.NotNull;

/**
 * Created by zlz
 * on  4/18/21
 */
public class ADSizeInfo extends BaseQuickAdapter<EntityGoodsSizeInfo, BaseViewHolder> {
    public ADSizeInfo() {
        super(R.layout.item_size_info);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, EntityGoodsSizeInfo entity) {

        holder.setText(R.id.tvBatch,entity.getBatch());
        holder.setText(R.id.tvDays,entity.getDays());
        holder.setText(R.id.tvNum,entity.getNum());
        holder.setText(R.id.tvPrice,entity.getPrice());

        String gain = entity.getGain();

        ForegroundColorSpan foregroundColorSpan;

        if(gain.startsWith("+")){

            foregroundColorSpan = new ForegroundColorSpan(ContextCompat.getColor(getContext(),
                    R.color.colorFE4C40));

            SpannableString spannableString = new SpannableString(gain);

            spannableString.setSpan(foregroundColorSpan,0,gain.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

            holder.setText(R.id.tvGain,spannableString);

        }else if(gain.startsWith("-")){

            foregroundColorSpan = new ForegroundColorSpan(ContextCompat.getColor(getContext(),
                    R.color.color5B8C00));

            SpannableString spannableString = new SpannableString(gain);

            spannableString.setSpan(foregroundColorSpan,0,gain.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

            holder.setText(R.id.tvGain,spannableString);
        }else {

            holder.setText(R.id.tvGain,gain);
        }

        if(holder.getAdapterPosition() == getData().size()-1){

            holder.itemView.setBackgroundResource(R.drawable.item_bottom_corner);

        }else {

            holder.itemView.setBackgroundResource(0);
            holder.itemView.setBackgroundColor(Color.WHITE);



        }


    }
}
